import 'dart:convert';
import 'dart:ffi';

import 'package:example_example/bean/ToTaskBean.dart';
import 'package:example_example/pages/view/ItemToDoTaskView.dart';
import 'package:example_example/pages/view/LoadingDialog.dart';
import 'package:example_example/services/ScreenAdapter.dart';

import '../../../YColors.dart';
import '../../../pages/view/LoadingView.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import '../../../global/Global.dart';
import '../../../global/GlobalUrl.dart';
import '../../../services/TLSizeFit.dart';
import '../../../util/HttpUtil.dart';
import '../../../util/LogUtil.dart';
import '../../../util/ToastUtils.dart';
import '../../../util/Storage.dart';
import '../../../pages/person/Login.dart';
import '../../view/ItemFinishTaskView.dart';
import '../../view/HeaderView.dart';
import '../../view/NoDataView.dart';
import '../../../services/EventBus.dart';
import '../../../util/TodoHttputil.dart';
import '../../../util/MathUtils.dart';
import '../../view/ExpandedText.dart';
import '../../../util/HttpMethod.dart';

/**刷新来自官网的demo
 * flutter_easyrefresh   刷新的第三方组件
 * https://pub.dev/packages/flutter_easyrefresh/example
 *
 * 办结任务
 *
 */

class PoOrderPage extends StatefulWidget {
  PoOrderPage({Key key}) : super(key: key);

  _PoOrderPageState createState() => _PoOrderPageState();
}

/**
    没有用了
 */
setMyShow(flagSel) {
  print("去显示区吧$flagSel");
//  showSelectFlag = flagSel;
}

class _PoOrderPageState extends State<PoOrderPage> {
  EasyRefreshController _controller;

  // 条目总数
//  int _count = 6; //20

  List dataList = [];
  int pageIndex = 1;
  bool noDataflag = false;

  List selectedList = [];

  bool allSelectFlag = false;

  bool myShowSelectFlag = false;

  var eventBusFn;

  @override
  void initState() {
    super.initState();
    LogUtil.v("待办任务 PO。。。。initState");
    _controller = EasyRefreshController();

    LogUtil.v("po页面... initState....myShowSelectFlag:$myShowSelectFlag");

    initHttpData();
    HttpMethod.initDictionaryData(this.context);

    /**
     * 广播接收；
     */
    eventBusFn = eventBus.on<ApplySelectEvent>().listen((event) {
      print("收到了广播event:$event");
      myShowSelectFlag = event.showSelectFlag;
      print("myShowSelectFlag:$myShowSelectFlag");

      setAllNoSelect();
      selectedList.clear();
      setState(() {
        dataList = dataList;
      });
    });

    /**
     * 广播接收； H5审批成功后，刷新
     */
    eventBusFn = eventBus.on<ReFresshEvent>().listen((event) {
      print("4444收到了广播event:${event.reFreshFLag}");
      if(event.reFreshFLag =="4"){  // 去刷新数据
        print("444去刷新了");
        initHttpData();
      }

    });

  }

  @override
  Widget build(BuildContext context) {
    LogUtil.v("po页面....build");
    LogUtil.v("待办任务 PO。。。。initState");
    return Scaffold(
//        appBar: AppBar(
//          title: Text("EasyRefresh"),
//        ),
      body: Stack(
        children: <Widget>[
          Container(
            height: myShowSelectFlag
                ? TLSizeFit.setPx(TLSizeFit.screenHeight - TLSizeFit.setPx(146))
                : TLSizeFit.setPx(TLSizeFit.screenHeight),
            child: EasyRefresh.custom(
              enableControlFinishRefresh: false,
              // 是否开启控制结束刷新
              enableControlFinishLoad: true,
              // 是否开启控制结束加载
              controller: _controller,
              // EasyRefresh控制器
//          header: ClassicalHeader(),
              header: ClassicalHeader(
                enableInfiniteRefresh: false,
                refreshText: "拉动刷新",
                refreshReadyText: "释放刷新",
                refreshingText: "正在刷新...",
                refreshedText: "刷新完成",
                refreshFailedText: "刷新失败",
                noMoreText: "没有更多数据",
                showInfo: false, // 是否显示时间
//            infoText: "更新于 %T",
              ),
//          footer: ClassicalFooter(),
              footer: ClassicalFooter(
                loadText: "拉动加载",
                loadReadyText: "释放加载",
                loadingText: "正在加载...",
                loadedText: "加载完成",
                loadFailedText: "加载失败",
                noMoreText: "没有更多数据",
                infoText: "更新于 %T",
              ),
              onRefresh: () async {
                print('onRefresh');
                pageIndex = 1;
//                allSelectFlag = false;
                initHttpData();
//          await Future.delayed(Duration(seconds: 2), () {
//
//          });
              },
              onLoad: () async {
                print('onLoad');
                pageIndex++;
//                allSelectFlag = false;
                initHttpData();
//          await Future.delayed(Duration(seconds: 2), () {
//
////            _controller.finishLoad(noMore: _count >= 40);
//          });
              },
              slivers: <Widget>[
                SliverList(
                  delegate: SliverChildBuilderDelegate(
                    (context, index) {
                      if (dataList != null && dataList.length > 0) {
                        return InkWell(
                          child: ItemToDoTaskView(context, dataList[index],
                              index, getPoOrderType(dataList[index])),
                          onTap: () {
                            showDialog(
                                context: context,
                                barrierDismissible: true,
                                builder: (_) {
                                  return new LoadingDialog(text: "努力加载中");
                                });
                            setToDoNet(context, dataList[index],"4");

//                            String processInstanceId =
//                                dataList[index]["processInstanceId"];
//                            print("查看流程图processInstanceId:$processInstanceId");
//                            if (processInstanceId == null) {
//                              processInstanceId = "";
//                            }
//                            String url = GlobalUrl.WEB_CHART_URL +
//                                "?processInstanceId=" +
//                                processInstanceId +
//                                "&platform=app";
//                            Navigator.pushNamed(context, '/webViewUtilPage',
//                                // webViewUtilPage   WebViewExample
//                                arguments: {
//                                  Global.WEBVIEW_TAG: Global.HIISTORYTASK,
//                                  Global.WEBVIEW_URL: url,
//                                }).then((value) {
//                              //HELP
//                              print('webview:$value');
//                            });
                          },
                        );
                      } else {
                        return Container(
                          height: TLSizeFit.screenHeight - 200,
                          alignment: Alignment.center,
                          child: Center(
                            child: Text('还没有数据哦'),
                          ),
                          color: Colors.transparent,
                        );
                      }
                    },
//              childCount: dataList.length==0?1:dataList.length,
                    childCount: dataList.length,
                  ),
                ),
              ],
            ),
          ),
          (this.dataList.length <= 0 && !noDataflag)
              ? LoadingView()
              : Container(),
          noDataflag ? NoDataView() : Container(),
          myShowSelectFlag ? setBottomApply() : Container(),
        ],
      ),
    );
  }

  /**
   * 设置按钮未选择状态
   */
  setAllNoSelect() {
    for (var i = 0; i < dataList.length; i++) {
      var name = dataList[i]["name"];
//      LogUtil.v("name:$name");
      dataList[i]["selectFlag"] = false; // 赋值
//      if(allSelectFlag){
//        dataList[i]["selectFlag"] = true; // 赋值
//        setAllSelect();
//      }else{
//        dataList[i]["selectFlag"] = false; // 赋值
//      }

    }
  }

  /**
   * 接口获取的数据设置显示的标记
   * 设置显示批量选择的选择按钮
   */
  setRefreshSelect(list) {
    for (var i = 0; i < list.length; i++) {
      var name = list[i]["name"];
//      LogUtil.v("name:$name");

      /**
       * pageIndex==1 是下拉刷新的时候
       * 如果全选了，记录全选的功能；
       * 没有全选就全部置为未选状态；
       */
      if (pageIndex == 1) {
        if (allSelectFlag) {
          list[i]["selectFlag"] = true; // 赋值
        } else {
          list[i]["selectFlag"] = false; // 赋值
          selectedList.clear(); //清空数据
        }
      } else {
        //  上拉加载
        list[i]["selectFlag"] = false; // 赋值
      }
    }

    /**
     * 当第一页全选以后，上拉加载第二页数据，那么此时应该将全选按钮的勾选去掉，
     */
    setAllState();
    /**
     *
     * 如果 有两页以上的数据，然后又点击了全选按钮后，
     * 此时又去下拉刷新了，那么刷新的数据就应该是第一页的10条数据，
     * 就去重置一下已选的数据；
     *
     */
    if (allSelectFlag && pageIndex == 1) {
      setAllSelect();
    }
  }

  /**
   * 全选按钮的状态，单次修改
   */
  setAllState() {
    if (dataList.length == 0) {
      return;
    }
    print("dataList.length${dataList.length}");
    print("selectedList.length${selectedList.length}");
    if (dataList.length == selectedList.length) {
      setState(() {
        allSelectFlag = true;
      });
    } else {
      setState(() {
        allSelectFlag = false;
      });
    }
  }

  /**
   * 审批的布局
   */
  Widget setBottomApply() {
    return Positioned(
        bottom: 0,
        child: Container(
          padding: EdgeInsets.fromLTRB(
              TLSizeFit.setPx(20), 0, TLSizeFit.setPx(20), 0),
          width: TLSizeFit.screenWidth,
          height: TLSizeFit.setPx(40),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              InkWell(
                child: Row(
                  children: <Widget>[
                    Image.asset(
                      allSelectFlag
                          ? "images/order_select_all.png"
                          : "images/order_unselect.png",
                      width: TLSizeFit.setPx(20),
                      height: TLSizeFit.setPx(20),
                    ),
                    SizedBox(
                      width: TLSizeFit.setPx(6),
                    ),
                    Text("全选", style: TextStyle(color: YColors.l)),
                  ],
                ),
                onTap: () {
                  print("去全选了");
                  allSelectFlag = !allSelectFlag;
                  setAllSelect();
                },
              ),
              TextButton(
                  onPressed: () {
                    print("去审批了");
                    if (selectedList != null && selectedList.length > 0) {
                      _applyDialog();
                    } else {
                      ToastUtils.toast("请先选择一条数据");
                    }
                  },
                  child: Text("审批", style: TextStyle(color: YColors.l))),
            ],
          ),
          decoration: BoxDecoration(
            // 边框 zj
            color: YColors.t, // 背景色 zj
            border: Border(
                top: BorderSide(color: YColors.dividerColor, width: 0.3)),
          ),
        ));
  }

  /**
   * 全选的方法
   */
  setAllSelect() {
    print("allSelectFlag：$allSelectFlag");

    if (allSelectFlag) {
      //全选
      selectedList.clear();
      for (var i = 0; i < dataList.length; i++) {
        print("集合里的数据：${dataList[i]["id"]}");
        var seleBean = {};
        seleBean["id"] = dataList[i]["id"];
        seleBean["taskDefinitionKey"] = dataList[i]["taskDefinitionKey"];
        selectedList.add(seleBean);
        dataList[i]["selectFlag"] = true; // 赋值
      }
      setState(() {
        dataList = dataList;
      });
    } else {
      setAllNoSelect();
      selectedList.clear();
      setState(() {
        dataList = dataList;
      });
    }
  }

  /**
   * 审批弹出框
   * */
  _applyDialog() async {
    //
    var result = await showDialog(
        //
        barrierDismissible: false, //表示点击灰色背景的时候是否消失弹出框
        context: context,
        builder: (context) {
          return AlertDialog(
            title: Text("提示信息"),
//            content: Text("您确定删除吗?"),
            actions: <Widget>[
              FlatButton(
                  child: Text("通过"),
                  onPressed: () {
                    print("通过");
                    applyHttp("1");
                  }),
              FlatButton(
                  child: Text("不通过"),
                  onPressed: () {
                    print("不通过");
                    applyHttp("2");
                  }),
              FlatButton(
                  child: Text("取消"),
                  onPressed: () {
                    print("取消");
                    Navigator.pop(context, "sure"); // 关闭
                  }),
            ],
          );
        });

    print("点击了返回${result}");
  }

  /**
   * 显示的每一个条目
   *  poOrderType
   *  11& 15  正常
      12&14  设备
      13 人员
   */
  Widget ItemToDoTaskView(context, bean, position, orderType) {
    // TODO: implement build
    return Container(
      width: double.infinity,
      margin: EdgeInsets.fromLTRB(
          TLSizeFit.setPx(20), TLSizeFit.setPx(20), TLSizeFit.setPx(20), 0),
      padding: EdgeInsets.fromLTRB(TLSizeFit.setPx(20), TLSizeFit.setPx(4),
          TLSizeFit.setPx(20), TLSizeFit.setPx(20)),
      child: Stack(
//        mainAxisAlignment: MainAxisAlignment.start,
//        crossAxisAlignment: CrossAxisAlignment.start,
//      direction: Axis.horizontal,  Wrap

        children: <Widget>[
          myShowSelectFlag
              ? Container(
//                  height: 60,
//            color: YColors.l,
                  padding: EdgeInsets.fromLTRB(
                      0, TLSizeFit.setPx(14), TLSizeFit.setPx(15), 0),
                  child: InkWell(
                    child: Image.asset(
                      bean["selectFlag"]
                          ? "images/order_selected.png"
                          : "images/order_unselect.png",
                      width: TLSizeFit.setPx(20),
                      height: TLSizeFit.setPx(20),
                    ),
                    onTap: () {
                      print("选择了我了position:$position");
                      setState(() {
                        bean["selectFlag"] = !bean["selectFlag"];

                        if (bean["selectFlag"]) {
                          var seleBean = {};
                          seleBean["id"] = bean["id"];
                          seleBean["taskDefinitionKey"] =
                              bean["taskDefinitionKey"];
                          selectedList.add(seleBean);
                        } else {
                          print("选择了：${bean["id"]}");
                          for (var i = 0; i < selectedList.length; i++) {
                            print("集合里的数据：${selectedList[i]["id"]}");
                            if (selectedList[i]["id"] == bean["id"]) {
                              print("是否删除了啊${selectedList[i]}");
                              selectedList.remove(selectedList[i]);
                              break;
                            }
                          }
                        }

                        for (var i = 0; i < selectedList.length; i++) {
                          var id = selectedList[i]["id"];
                          print("都选择了id:$id");
                        }
                      });
                      setAllState();
                    },
                  ),
                )
              : Container(
                  width: TLSizeFit.setPx(0),
                ),
         Container(
           margin: EdgeInsets.fromLTRB( myShowSelectFlag ? TLSizeFit.setPx(40):0, 0, 0, 0),
           child: Column(
           crossAxisAlignment: CrossAxisAlignment.start,
           children: <Widget>[
             SizedBox(
               height: TLSizeFit.setPx(10),
             ),
             Row(
               children: <Widget>[
                 Text(
//              bean["name"] != null ? bean["name"] : "",
                   bean["processDefinitionName"] != null
                       ? bean["processDefinitionName"]
                       : "",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(34),
                     color: YColors.a,
                   ),
                 ),
               ],
             ),
             SizedBox(
               height: TLSizeFit.setPx(14),
             ),

             (orderType == "12" || orderType == "13" || orderType == "14")
                 ?
             Row(
               crossAxisAlignment: CrossAxisAlignment.start,
               children: <Widget>[
                 Text(
                   "项目名称:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 ExpandedText(getBusinessName(bean),color:YColors.c),
//                ExpandedText("卡机的反馈骄傲肯德基发卡机的非框架艾迪康垃圾分类口阿卡决胜巅峰看就的",color:YColors.c),
//                        Text(
//                          getBusinessName(bean),
//                          style: TextStyle(
//                            fontSize: ScreenAdapter.size(28),
//                            color: YColors.c,
//                          ),
//                        ),
               ],
             )
                 : Container(),

             SizedBox(
               height: (orderType == "12" || orderType == "13" || orderType == "14")?TLSizeFit.setPx(10):0,
             ),
             orderType == '13'
                 ? Row(
               crossAxisAlignment: CrossAxisAlignment.start,
               children: <Widget>[
                 Text(
                   "服务名称:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 ExpandedText(getServiceName(bean),color:YColors.c),
//                 IntrinsicHeight(child:ExpandedText(getServiceName(bean),color:YColors.c)),
//                 Text(
//                   getServiceName(bean),
//                   style: TextStyle(
//                     fontSize: ScreenAdapter.size(28),
//                     color: YColors.c,
//                   ),
//                 ),
               ],
             )
                 : Container(),
             SizedBox(
               height: orderType == '13'?TLSizeFit.setPx(10):0,
             ),

             (orderType == '11'||orderType == '15')
                 ? Row(
               children: <Widget>[
                 Text(
                   "业务名称:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 Text(
                   getBusinessName(bean),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             )
                 : Container(),
             SizedBox(
               height: (orderType == '11'||orderType == '15')?TLSizeFit.setPx(10):0,
             ),

             (orderType == '11'||orderType == '15')
                 ? Row(
               children: <Widget>[
                 Text(
                   "开始时间:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 Text(
                   bean["createTime"] != null ? bean["createTime"] : "",
//              getDataStatusText(bean),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             ):Container(),

             SizedBox(
               height: (orderType == '11'||orderType == '15')?TLSizeFit.setPx(10):0,
             ),

             (orderType == '11'||orderType == '15')
                 ? Row(
               children: <Widget>[
                 Text(
                   "状态:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(36),
                 ),
                 Text(
                   getDataStatusText(bean),
//              getDataStatusText(bean),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             ):Container(),
             SizedBox(
               height: (orderType == '11'||orderType == '15')?TLSizeFit.setPx(10):0,
             ),

             orderType == '13'?Row(
               children: <Widget>[
                 Text(
                   "订单金额:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 Text(
                   getDindDanJingE(bean).toString(),
//              getDataStatusText(bean),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             ):Container(),

             SizedBox(
               height:  orderType == '13'?TLSizeFit.setPx(10):0,
             ),

             orderType == '13'?Row(
               children: <Widget>[
                 Text(
                   "工单金额:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 Text(
//              "状态。。。。。",
//              bean["status"]!=null? bean["status"]:"",
//                    getDataStatusText(bean),
                   getGongDanJingE(bean).toString(),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             ):Container(),

             SizedBox(
               height: orderType == '13'?TLSizeFit.setPx(10):0,
             ),

             orderType == '13'?Row(
               children: <Widget>[
                 Text(
                   "人员类型:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 Text(
//              "状态。。。。。",
//              bean["status"]!=null? bean["status"]:"",
//                    getDataStatusText(bean),
                   getSupplierType(bean),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             ):Container(),

             SizedBox(
               height:  orderType == '13'?TLSizeFit.setPx(10):0,
             ),

             (orderType == '12'|| orderType == '14')?Row(
               children: <Widget>[
                 Text(
                   "申请采购价格:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(8),
                 ),
                 Text(
//                    MathUtils.returnFloatTwo(getGongDanJingE(bean)),
//                    getGongDanJingE(bean).toStringAsFixed(2),
                   getGongDanJingE(bean),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             ):Container(),

             SizedBox(
               height:  (orderType == '12'|| orderType == '14')?TLSizeFit.setPx(10):0,
             ),

             (orderType == '12'|| orderType == '14')?Row(
               children: <Widget>[
                 Text(
                   "设备数量:",
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
                 SizedBox(
                   width: TLSizeFit.setPx(36),
                 ),
                 Text(
//              bean["status"]!=null? bean["status"]:"",
//                    getDataStatusText(bean),
                   getEquipmentListCount(bean),
                   style: TextStyle(
                     fontSize: ScreenAdapter.size(28),
                     color: YColors.c,
                   ),
                 ),
               ],
             ):Container(),

//        InkWell(
//          child: Container(
//            padding: EdgeInsets.fromLTRB(0, 10, 0, 10),
//            width: double.infinity,
////            color: YColors.l,
//            child: Row(
//              children: <Widget>[
//                Container(
//                  padding: EdgeInsets.fromLTRB(7, 4, 7, 4),
////                  color: YColors.m,
//                  child: Text(
//                    "查看流程图",
//                    style: TextStyle(
//                      fontSize: 14.0,
//                      color: YColors.a,
//                    ),
//                  ),
//
//                  decoration: BoxDecoration(
//                    color: YColors.m,
//                    borderRadius: BorderRadius.all(new Radius.circular(4)),
//                  ),
//                ),
//              ],
//            ),
//          ),
//          onTap: () {
//            print("查看流程图");
//            String processInstanceId = bean["processInstanceId"];
//            print("查看流程图processInstanceId:$processInstanceId");
//            if (processInstanceId == null) {
//              processInstanceId = "";
//            }
//            String url = GlobalUrl.WEB_CHART_URL +
//                "?processInstanceId=" +
//                processInstanceId +
//                "&platform=app";
//            Navigator.pushNamed(context, '/webViewUtilPage', //WebViewExample
//                arguments: {
//                  Global.WEBVIEW_TAG: Global.HIISTORYTASK,
//                  Global.WEBVIEW_URL: url,
//                }).then((value) {
//              print('webview:$value');
//            });
//          },
//        ),
           ],
         ),),
        ],
      ),
      decoration: BoxDecoration(
          // 边框 zj
          color: YColors.t, // 背景色 zj
//        border: Border.all(
//          // 边框 zj
//            color: Colors.black12, // 边框颜色 zj
//            width: 1.0 // 边框宽度 zj
//
//        ),
          borderRadius: BorderRadius.all(// 圆角
              //  Radius.circular(150),    //圆形
              Radius.circular(4) // 圆角 zj
              ),
          boxShadow: [
            BoxShadow(
//                            color: Colors.black12,
//              color: Color(0x554CBC5A), // 55  是透明度
                color: Color(0x12000000), // 55  是透明度
                offset: Offset(0.0, 2.0), //阴影xy轴偏移量
                blurRadius: 4.0, //阴影模糊程度
                spreadRadius: 1 //阴影扩散程度
                )
          ]

//            // 设置单圆角：左上角的圆角为5，右上角的圆角为10
//            borderRadius: BorderRadius.only(
//                    topLeft: Radius.circular(5),
//                   topRight: Radius.circular(10),
//              ),

          ),
    );
  }

  /**
   * 获取类型
   */
  String getPoOrderType(bean) {
    var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
    variableJson = json.decode(variableJson);
    var poOrderType = variableJson["poOrderType"]; //ppProjectName
    LogUtil.v("poOrderType:$poOrderType");
    if (poOrderType == null) {
      poOrderType = "";
    }

    return poOrderType;
  }

  /**
   * 服务名称
   */
  String getServiceName(bean){
    var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
    variableJson = json.decode(variableJson);
    var pomServiceTitle = variableJson["pomServiceTitle"]; //ppProjectName
    LogUtil.v("pomServiceTitle:$pomServiceTitle");
    if (pomServiceTitle == null) {
      pomServiceTitle = "";
    }

    return pomServiceTitle;

  }



  /**
   * 状态
   */
  String getDataStatusText(bean) {
    var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
    variableJson = json.decode(variableJson);
    var statusText = variableJson["statusText"]; //statusText
//  LogUtil.v("statusText:$statusText");
    if (statusText == null) {
      statusText = "";
    }
    return statusText;
  }


  /**
   * 订单金额
   */
  String getDindDanJingE(bean) {  //  double
    var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
    variableJson = json.decode(variableJson);
    var pomEventAmount = variableJson["pomEventAmount"]; //ppProjectName
    LogUtil.v("订单金额pomEventAmount:$pomEventAmount");
    if (pomEventAmount == null) {
      pomEventAmount = 0;
    }
    pomEventAmount = pomEventAmount.toStringAsFixed(2); // 保留两位小数
    return pomEventAmount;
  }

  /**
     * 订单金额/ 采购价格
     */
  String getGongDanJingE(bean) {  //  double
    var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
    variableJson = json.decode(variableJson);
    var poApplicationPrice = variableJson["poApplicationPrice"]; //ppProjectName
    LogUtil.v("订单金额poApplicationPrice:$poApplicationPrice");
    if (poApplicationPrice == null) {
      poApplicationPrice = 0;
    }
    poApplicationPrice = poApplicationPrice.toStringAsFixed(2); // 保留两位小数

    return poApplicationPrice;
  }

  /**
   * 人员类型
   *  人员类型：1：个人；2：企业；
   */
  String getSupplierType(bean) {  //  double
    var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
    variableJson = json.decode(variableJson);
    String poSupplierType = variableJson["poSupplierType"]; //ppProjectName
    LogUtil.v("供应商类型poSupplierType:$poSupplierType");
    if(poSupplierType!=null && poSupplierType!=""){
      if(poSupplierType == "1"){
        return "个人";
      } else {
        return "企业";
      }
    }
    return "";
  }


  /**
   *  设备数量
   */
  String getEquipmentListCount(bean) {  //  double
    var variableJson = bean['variableJson'];
//  LogUtil.v("variableJson:$variableJson");
    variableJson = json.decode(variableJson);
    var equipmentListCount = variableJson["equipmentListCount"]; //ppProjectName poApplicationPrice poaApprovalStatus
    LogUtil.v("供应商类型equipmentListCount:$equipmentListCount");
    if(equipmentListCount==null ){
      equipmentListCount = "";
    }
    return equipmentListCount.toString();
  }




  initHttpData() async {
//    http://10.66.1.100:8181/api/us-process/process/pageFinished?current=1&size=10

    String apiUrlhttp = GlobalUrl.PROCESSTASK;
    var map = {
      "processDefinitionKeys":
          "poInformalProcess,poNotMaintenanceProcess,poEquipmentProcess,poManpowerProcess",
      "current": pageIndex,
      "size": "10",
    };
    String access_token = await Storage.getToken();
    LogUtil.init(title: "来自LogUtil", isDebug: false, limitLength: 800);
    var mapHeaders = {
      Global.AUTHORIZATION: access_token,
      Global.CONTENT_TYPE: Global.APPLICATION_JSON
    };
    HttpUtil.get(apiUrlhttp, data: map, headers: mapHeaders, success: (data) {
      // 下拉刷新停止
      _controller.resetLoadState();
      //  上拉加载停止
      _controller.finishLoadCallBack();
//    _controller.finishLoad(noMore: false);
      _controller.finishLoad();

      var success = data["success"];
//      LogUtil.v("success:$success");
      var message = data["msg"];
      var body = data["data"];
      var code = data["code"];
//      LogUtil.v("body:$body");
      if (success != null && success == true) {
        LogUtil.v("进来了");
        List getList = body["records"];
//        LogUtil.v("getList:$getList");
        LogUtil.v("获取的接口数据：${getList.length}");

        if (myShowSelectFlag) {
          setRefreshSelect(getList);
        }

        if (pageIndex == 1) {
          dataList.clear();
          dataList.addAll(getList);
        } else {
          dataList.addAll(getList);
        }
        print(dataList.length);

        if (dataList.length == 0) {
          setState(() {
            noDataflag = true;
          });
        } else {
          setState(() {
            dataList = dataList;
            noDataflag = false;
          });
        }
      }
    }, error: (errorMsg) {
      print("待办任务..PO..errorMsg: $errorMsg");
      // 下拉刷新停止
      _controller.resetLoadState();

      //  上拉加载停止
      _controller.finishLoadCallBack();
//            _controller.finishLoad(noMore: false);
      _controller.finishLoad();
    });
  }

  /**
   * 审核的接口访问
   */
  applyHttp(approvalStatus) async {
    String url = GlobalUrl.TASK_AUDITBATCH;

//    String strBody = json.encode(this.selectedList); // Map 转换成 Json 字符串
    var map = {
      "approvalStatus": approvalStatus, // 审批通过
      "taskList": this.selectedList,
    };

    String access_token = await Storage.getToken();
    LogUtil.init(title: "来自LogUtil", isDebug: false, limitLength: 800);
//    LogUtil.v("获取的access_token：$access_token");
//    Global.ACCESS_TOKEN_VALUE =  access_token.substring(7, access_token.length);  // 7

    var mapHeaders = {
      Global.AUTHORIZATION: access_token,
      Global.CONTENT_TYPE: Global.APPLICATION_JSON
    };

    HttpUtil.post(url, data: map, headers: mapHeaders, success: (data) {
      print("审批通过的数据data:$data");
//      审批通过的数据data:{code: 400, success: false, data: null, msg: 提交的审批任务中包含需要录入信息的任务}
//          {"code":"200","success":true,"data":null,"msg":"操作成功"}
      var toTaskBean = ToTaskBean.fromJson(data);
      var msg = toTaskBean.msg;
      if (toTaskBean.success) {
        Navigator.pop(context);
        initHttpData();
      }
      ToastUtils.toast(msg);
    }, error: (errorMsg) {
      print("审批报错errorMsg:$errorMsg");
    });
  }

  @override
  void dispose() {
    super.dispose();
    //取消订阅
    eventBusFn.cancel();
    _controller.dispose();
  }
}
